package com.mySpringMvc.web.servlet.view;

import com.mySpringMvc.web.servlet.View;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.util.Map;

/**
 * @program: mySSM
 * @description: 内部资源视图接口的实现类
 * @author:wjp
 * @create: 2025-02-13 18:28
 **/
public class InternalResourceView implements View {

    private String contentType;

    private String path;

    public InternalResourceView() {
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    @Override
    public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        // model数据一般放在请求作用域中
        model.forEach(request::setAttribute);
        // 视图渲染，默认使用request进行转发
        request.getRequestDispatcher(path).forward(request,response);
    }
}
